﻿using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using MoviesWebsite.Models;
using System.Data.Services.Providers;
using System.Data.Objects;
using System.Data.Entity;
using ActionProviderImplementation;
using Microsoft.Data.OData;
using System.Data.Services.Client;

namespace MoviesWebsite
{
    public class MoviesService : DataService<MoviesModel>, IServiceProvider
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
            config.SetEntitySetAccessRule("EdmMetadatas", EntitySetRights.None);
            config.SetEntitySetAccessRule("Users", EntitySetRights.None);
            config.SetEntitySetAccessRule("Rentals", EntitySetRights.None);
            config.SetEntitySetAccessRule("Ratings", EntitySetRights.None);
            config.SetServiceActionAccessRule("*", ServiceActionRights.Invoke);
            config.SetEntitySetPageSize("*", 100);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }

        public object GetService(Type serviceType)
        {
            if (typeof(IDataServiceActionProvider) == serviceType)
            {
                return new EntityFrameworkActionProvider(CurrentDataSource);
            }
            return null;
        }
    }
}
